package com.edais.dao;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.edais.domain.AllAccessToken;
import com.edais.domain.Signature;
import com.edais.domain.WeixinMediaBinding;
import com.edais.persistence.WeixinBindingMapper;

@Repository
public class WeixinBindingDao {	
	@Autowired
	private WeixinBindingMapper weixinBindingMapper;

	public void insertIntoMediaBinding(WeixinMediaBinding mediaBinding) {
		// TODO Auto-generated method stub
		int count = weixinBindingMapper.queryInfoMediaBinding(mediaBinding);
		if(count == 0){
			weixinBindingMapper.insertIntoMediaBinding(mediaBinding);
		}else{
			String uid  = weixinBindingMapper.queryMediaUid(mediaBinding);
			if(null == uid || "".equalsIgnoreCase(uid) || "null".equalsIgnoreCase(uid)){
				if(null!= mediaBinding.getMediaUid() && !"".equalsIgnoreCase(mediaBinding.getMediaUid()) && !"null".equalsIgnoreCase(mediaBinding.getMediaUid())){
					weixinBindingMapper.updateIntoMediaBinding(mediaBinding);
				}
			}
		}
		
	}

	public int queryInfoMediaBinding(WeixinMediaBinding mediaBinding) {
		// TODO Auto-generated method stub
		return weixinBindingMapper.queryInfoMediaBinding(mediaBinding);
	}

	public Map<String, Object> getSignature() {
		// TODO Auto-generated method stub
		return weixinBindingMapper.getSignature();
	}

	public void updateSignature(Map map) {
		// TODO Auto-generated method stub
		weixinBindingMapper.updateSignature(map);
	}

	public void insertSignature(Signature signTrue) {
		// TODO Auto-generated method stub
		weixinBindingMapper.insertSignature(signTrue);
	}

	public Map<String,String> getUseridByWeixinUid(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return weixinBindingMapper.getUseridByWeixinUid(map);
	}

	public Map<String, String> getWeixinUidBindingByMobile(Map<String, Object> map) {
		return weixinBindingMapper.getWeixinUidBindingByMobile(map);
	}

	public Map<String, Object> getAllToken() {
		// TODO Auto-generated method stub
		return weixinBindingMapper.getAllToken();
	}

	public void insertAllToken(AllAccessToken aat) {
		// TODO Auto-generated method stub
		weixinBindingMapper.insertAllToken(aat);
	}

	public void updateAllToken(Map<String, String> paramsMap) {
		// TODO Auto-generated method stub
		weixinBindingMapper.updateAllToken(paramsMap);
	}

	public String queryMediaUid(WeixinMediaBinding mediaBinding) {
		// TODO Auto-generated method stub
		return weixinBindingMapper.queryMediaUid(mediaBinding);
	}
}
